package com.stars.easyms.base.boot;

import com.stars.easyms.base.constant.EasyMsCommonConstants;
import com.stars.easyms.base.util.EasyMsVersion;
import com.stars.easyms.base.util.SpringBootUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * <p>className: EasyMsSpringBootLoggerListener</p>
 * <p>description: SpringBoot版本的监听器</p>
 *
 * @author guoguifang
 * @date 2019-12-27 14:05
 * @since 1.5.0
 */
public class EasyMsSpringBootListener implements SpringApplicationRunListener, Ordered {

    public EasyMsSpringBootListener(SpringApplication application, String[] args) {
        SpringBootUtil.setSpringApplication(application, args);
        System.setProperty(EasyMsCommonConstants.EASY_MS_PROPERTIES_PREFIX + "version", EasyMsVersion.getVersion());
    }

    @Override
    public void starting() {
        // Intentionally blank
    }

    @Override
    public void environmentPrepared(ConfigurableEnvironment environment) {
        // Intentionally blank
    }

    @Override
    public void contextPrepared(ConfigurableApplicationContext context) {
        // Intentionally blank
    }

    @Override
    public void contextLoaded(ConfigurableApplicationContext context) {
        // Intentionally blank
    }

    @Override
    public void started(ConfigurableApplicationContext context) {
        // Intentionally blank
    }

    @Override
    public void running(ConfigurableApplicationContext context) {
        // Intentionally blank
    }

    @Override
    public void failed(ConfigurableApplicationContext context, Throwable exception) {
        // Intentionally blank
    }

    @Override
    public int getOrder() {
        return HIGHEST_PRECEDENCE;
    }
}